package cn.iocoder.yudao.module.handguard.service.matchinginfo;

import cn.iocoder.yudao.module.handguard.controller.admin.order.vo.MemberUserBaseVO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.applicationrecord.ApplicationRecordDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.order.OrderDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.product.ProductDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.publicitytype.PublicityTypeDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.user.UserDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.usertablesaudit.UserTablesAuditDO;
import cn.iocoder.yudao.module.handguard.dal.mysql.applicationrecord.ApplicationRecordMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.order.OrderMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.product.ProductMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.publicitytype.PublicityTypeMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.usertablesaudit.UserTablesAuditMapper;
import cn.iocoder.yudao.module.handguard.service.user.MiniUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.matchinginfo.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.matchinginfo.MatchingInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.matchinginfo.MatchingInfoConvert;
import cn.iocoder.yudao.module.handguard.dal.mysql.matchinginfo.MatchingInfoMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 产品类型-补充资料内容-匹配 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class MatchingInfoServiceImpl implements MatchingInfoService {

    @Resource
    private MatchingInfoMapper matchingInfoMapper;

    @Resource
    private PublicityTypeMapper publicityTypeMapper;

    @Resource
    private UserTablesAuditMapper userTablesAuditMapper;

    @Resource
    private ProductMapper productMapper;

    @Resource
    private ApplicationRecordMapper applicationRecordMapper;

    @Resource
    private MiniUserService miniUserService;

    @Override
    public Long createMatchingInfo(MatchingInfoCreateReqVO createReqVO) {
        // 插入
        MatchingInfoDO matchingInfo = MatchingInfoConvert.INSTANCE.convert(createReqVO);
        matchingInfoMapper.insert(matchingInfo);
        // 返回
        return matchingInfo.getId();
    }

    @Override
    public void updateMatchingInfo(MatchingInfoUpdateReqVO updateReqVO) {
        // 校验存在
        validateMatchingInfoExists(updateReqVO.getId());
        // 更新
        MatchingInfoDO updateObj = MatchingInfoConvert.INSTANCE.convert(updateReqVO);
        matchingInfoMapper.updateById(updateObj);
    }

    @Override
    public void deleteMatchingInfo(Long id) {
        // 校验存在
        validateMatchingInfoExists(id);
        // 删除
        matchingInfoMapper.deleteById(id);
    }

    private void validateMatchingInfoExists(Long id) {
        if (matchingInfoMapper.selectById(id) == null)
            throw exception(MATCHING_INFO_NOT_EXISTS);
        }


    @Override
    public MatchingInfoDO getMatchingInfo(Long id) {
        return matchingInfoMapper.selectById(id);
    }

    @Override
    public List<MatchingInfoDO> getMatchingInfoList(Collection<Long> ids) {
        return matchingInfoMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<MatchingInfoDO> getMatchingInfoPage(MatchingInfoPageReqVO pageReqVO) {
        return matchingInfoMapper.selectPage(pageReqVO);
    }

    @Override
    public List<MatchingInfoDO> getMatchingInfoList(MatchingInfoExportReqVO exportReqVO) {
        return matchingInfoMapper.selectList(exportReqVO);
    }

}
